import apiClient from './config'
import type { 
  LoginRequest, 
  LoginResponse, 
  RegisterRequest, 
  ApiResponse 
} from './types'

export const authApi = {
  // 用户登录
  login: (data: LoginRequest): Promise<ApiResponse<LoginResponse>> => {
    return apiClient.post('/auth/login', data)
  },

  // 用户注册
  register: (data: RegisterRequest): Promise<ApiResponse<any>> => {
    return apiClient.post('/auth/register', data)
  },

  // 退出登录
  logout: (): Promise<ApiResponse<any>> => {
    return apiClient.post('/auth/logout')
  },

  // 刷新 token
  refreshToken: (): Promise<ApiResponse<{ token: string }>> => {
    return apiClient.post('/auth/refresh')
  },

  // 获取当前用户信息
  getCurrentUser: (): Promise<ApiResponse<LoginResponse>> => {
    return apiClient.get('/auth/me')
  },

  // 修改密码
  changePassword: (data: {
    oldPassword: string
    newPassword: string
    confirmPassword: string
  }): Promise<ApiResponse<any>> => {
    return apiClient.post('/auth/change-password', data)
  },

  // 忘记密码
  forgotPassword: (email: string): Promise<ApiResponse<any>> => {
    return apiClient.post('/auth/forgot-password', { email })
  },

  // 重置密码
  resetPassword: (data: {
    token: string
    password: string
    confirmPassword: string
  }): Promise<ApiResponse<any>> => {
    return apiClient.post('/auth/reset-password', data)
  }
}